import { isType } from './m.common';

/**
 * 从一个字符串中查找指定的字符是否存在
 * @param { string } str 需要查找的字符串
 * @param { Array<string> | string } ident 查找的字符串内容，可以是字符串，也可以是字符串数组
 * @param { boolean } absolute 是否绝对匹配
 * @returns { boolean } 是否可以查询到结果
 * **/
export const findString = (
    str: string,
    ident: Array<string> | string,
    absolute: boolean = false
): boolean => {
    if (isType(ident, 'array')) {
        const findFunction = absolute
            ? (item: string) => !str.includes(item)
            : (item: string) => str.includes(item);
        const result = (ident as Array<string>).find(findFunction);
        return absolute ? !result : !!result;
    }
    return !!str.includes(ident as string);
};
